//
//  CZJCMainTabBar.swift
//  SinaWeibo
//
//  Created by mac on 15/10/6.
//  Copyright © 2015年 cz. All rights reserved.
//

import UIKit

class CZJCMainTabBar: UITabBar {
    
    override func layoutSubviews() {
        super.layoutSubviews()
         var index: CGFloat = 0
        let w = UIScreen.mainScreen().bounds.width/5
        let h = self.bounds.height
        let frame = CGRectMake(0, 0, w, h)
        for view in subviews{
            if view is UIControl && !(view is UIButton){
            view.frame = CGRectOffset(frame, index*w, 0)
                if index == 1{
                    index++
                }
                index++
              
            }
        }
        //设置中间 按钮
        composeBtn.frame = CGRectOffset(frame, 2*w, 0)
    }
    
    //懒加载得到一个按钮
    lazy var composeBtn : UIButton = {
        let btn = UIButton(type: UIButtonType.Custom)
       btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        //添加到父控件
       self.addSubview(btn)
        
        return btn
        
    }()

}
